<?php

/**
 * Subclass for representing a row from the 'conf_specialevent' table.
 *
 * 
 *
 * @package lib.model
 */ 
class SpecialEvent extends BaseSpecialEvent
{

  public function getNbSpecialEventRegistrations()
  {  
    return $this->countSpecialEventRegistrations();
  }
  
  //is a special event full?
  public function isFull(){
	$a = $this->countSpecialEventRegistrations();
	$b = $this->getMaxEnroll();
	if($a >= $b){
		return true;
	}
	return false;
  }

#get name of the conference
  public function getConferenceName()
  {  
    return $this->getConference()->getName();
  }
  
  public static function totalSelectedSpecialEventsFee($selectedSpecialEvents)
  {
    $totalSelectedSpecialEventsFee = 0;
    
    foreach ($selectedSpecialEvents as $selectedSpecialEvent)
    {
      $totalSelectedSpecialEventsFee = $totalSelectedSpecialEventsFee + $selectedSpecialEvent->getFee();
    }
    return $totalSelectedSpecialEventsFee;
  }

  public static function getClashedSpecialEventIDs($specialEventIDArray)
  {
    $clashedIDArray = array ();
  
    foreach ($specialEventIDArray as $registeredSpecialEventID)
    {
      $c = new Criteria();
      $c->add(SpecialEventPeer::ID, $registeredSpecialEventID);
      $registeredSpecialEvent = SpecialEventPeer::doSelectOne($c);

      $c = new Criteria();
      $c->clearSelectColumns();
      $c->addSelectColumn(SpecialEventPeer::ID);
      $c->add(SpecialEventPeer::CONFERENCE_ID, $registeredSpecialEvent->getConferenceId());
      $c->addAnd(SpecialEventPeer::TIME_START, $registeredSpecialEvent->getTimeEnd(), Criteria::LESS_EQUAL); 
      $c->addAnd(SpecialEventPeer::TIME_END, $registeredSpecialEvent->getTimeStart(), Criteria::GREATER_EQUAL);
      
      $rsClashedSpecialEventIDs = SpecialEventPeer::doSelectRS($c);
              
      while($rsClashedSpecialEventIDs->next())
      {
        if (!in_array($rsClashedSpecialEventIDs->getInt(1), $clashedIDArray))
        {
          $clashedIDArray[] = $rsClashedSpecialEventIDs->getInt(1);
        }
        
      }
    }
    
    return $clashedIDArray;
  }


}
